<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use DB;

class PasswordController extends Controller
{
    //
    public function index()
    {
		return view('home.person.password');
    }

    public function update(Request $request)
    {
    // $oldpassword = $request->input('oldpassword');
    
    // $data = $request->all();
    // dd($newpassword);

    // $oldpass = md5($request->input('oldpassword'));
    // var_dump($oldpass);
    // $uid = session('id');
    // var_dump(DB::table('user')->where('id',$uid)->first()->userpwd);
    $uid = session('id');
    $data = DB::table('user')->where('id',$uid)->first();
    // dd($data);
    $a = md5($request->input('oldpassword'));
    // var_dump($data->userpwd);
    // var_dump(md5($request->input('oldpassword')));
    // dd(md5($request->input('oldpassword')) == $data->userpwd);
    // echo (md5($request->input('oldpassword')) == $data->userpwd);die;
    if(md5($request->input('oldpassword')) == $data->userpwd){
        echo 1;
    }else{
        echo 2;
    }

    // $newpassword = $request->input('userpwd');
    // dd($newpassword);
    // $data = DB::table('user')->where('id',$uid)->update($newpassword);
    // if($row>0){
    //         return redirect('home/person/password')->with('msg','修改成功');
    //     }else{
    //         return redirect('home/person/password')->with('error','修改失败');
    //     }

    }
    public function userpwd(Request $request)
    {
    $newpassword = $request->only('userpwd');
    $newpassword['userpwd']=md5($newpassword['userpwd']);
    $uid = session('id');
    // dd($newpassword);
    $res = DB::table('user')->where('id',$uid)->update($newpassword);
    if($res>0){
            session()->forget('id');
            return redirect('/doLogin')->with('msg','修改成功');
        }else{
            return redirect('home/person/password')->with('error','修改失败');
        }
    }


}
